<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <%@include file="../includes/common.jsp" %>
    <%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
    <%@ page contentType="text/html;charset=UTF-8" %>

    <title>论坛界面</title>
</head>
<body>
<div class="container-fluid" style="padding: 0">
    <div class="row-fluid">

        <div style="padding: 10px">
            <form class="form-inline">
                帖子名称：<input type="text" class="input-medium" name="topic" id="topic"  value=""/>

                <a class="btn btn-primary" onclick="query()">查找</a>
            </form>
            <table id="dataTable"></table>
            <div id="posts" style=" margin-top: 200px ;margin-left: 100px; width: 800px;height: 100px" >
                <label style="font-size: 20px;">帖子主题</label>
                <input type="text" style="width: 780px;" id="newTopic"/>
                <div style="width: 780px;height: 10px;text-align: right">
                    <input type="button" class="btn btn-primary" onclick="savePosts()" value="发表"/>

                </div>
            </div>
            <div id="dataEdit" closed="true" modal="true" style="overflow: hidden">
                <iframe style="width: 100%;height: 100%"
                        id="contentFrame"
                        name="contentFrame"
                        marginheight="0"
                        marginwidth="0"
                        frameborder="0" src=""
                        allowTransparency="true">
                </iframe>
            </div>




        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    function savePosts(){
        $.ajax({
            url: basePath + "consumer/addPosts",
            data: {
                topic:$("#newTopic").val().trim(),
                postTime: showLocale(new Date())
            },
            dataType:"json",
            type:"POST",
            success:function(){
                $.messager.alert("成功", "发表成功！", "", function () {
                query();
            })
            },
            error:doError

        });
    }

    function query() {
        listOption.url = basePath+"consumer/listAllPosts";
        listOption.data = "topic="+$("#topic").val().trim();
        listOption.pageNumber = 1;
        loadData(listOption);
    }

    function initDataGrid() {
        $('#dataTable').datagrid({
            title: "帖子列表",
            pagination: true,
            fitColumns: true,
            columns: [
                [
                    {field: 'topic', title: '帖子主题', sortable: true, align: 'center', width: 300},
                    {field: 'showPostPerson', title: '发帖人', sortable: true, align: 'center', width: 200},
                    {field: 'postTime', title: '发表时间', align: 'center', width: 300},
                    {field: 'replyNum', title: '帖子回复数量', align: 'center', width: 100},
                    {field: 'edit', title: '操作', align: 'center', width: 200}
                ]
            ],
            sortName: "",
            sortOrder: "",
            onSortColumn: onSortColumn
        });
    }

    function onSortColumn(sortColumn, sortDirection) {
        switch (sortColumn) {
            case "topic":
                sortColumn = "topic";
                break;

        }
        onSortColumnDefault(sortColumn, sortDirection);
    }

    function format(data) {
        data.resultList = queryFormat(data.resultList);
        return data;
    }

    function queryFormat(temp) {
        var rowDataList = [];
        for (var i in temp) {
            idBtn = "&nbsp;<input type='checkbox' name='deleteUserCheckBox' id='" + temp[i].id + "' value='" + temp[i].id + "'\">&nbsp;";
            editBtn = "&nbsp;<a onclick='checkPosts(\"" + temp[i].id + "\")'>查看</a>&nbsp;";
            temp[i].id = idBtn;
            temp[i].edit = editBtn;
            rowDataList.push(temp[i]);
        }
        return rowDataList;
    }

    function selectAll() {
        if ($("#checkAll").attr("checked") == "checked") {
            $("[name='deleteUserCheckBox']").attr("checked", true);
        } else {
            $("[name='deleteUserCheckBox']").attr("checked", false);
        }
    }
    function checkPosts(id){
       window.location.href=basePath+"consumer/findOnePost?postId="+id;
    }

    $(function () {
        initDataGrid();
        query();
    });
</script>